/*
   File: SsoTokenInfo.java
   Copyright 2004-2010 99Bill Corporation. All rights reserved.
   Created at   2011-8-31
   Author       zhe.yang
   Changed at   2011-8-31
 */

package com.bill99.golden.inf.sso.mdp.model;

import java.util.Date;

/**
 * SSO令牌信息
 */
public class SsoTokenInfo {
	/**
	 * 应用代码
	 */
	private String appCode;
	/**
	 * 校验码
	 */
	private String checkCode;
	/**
	 * 会员ID
	 */
	private String userId;

	/**
	 * 用户的IP
	 */
	private String userIp;
	/**
	 * 用户浏览器类型
	 */
	private String explorerType;

	/**
	 * 用户代码
	 */
	private String userCode;
	/**
	 * 用户名称
	 */
	private String userName;
	/**
	 * 组织ID
	 */
	private String orgId;
	/**
	 * 组织代码
	 */
	private String orgCode;
	/**
	 * 组织名称
	 */
	private String orgName;
	/**
	 * 部门ID
	 */
	private String departmentId;
	/**
	 * 部门代码
	 */
	private String departmentCode;
	/**
	 * 部门名称
	 */
	private String departmentName;
	/**
	 * 备注
	 */
	private String memo;
	/**
	 * 令牌更新时间
	 */
	private long updateTime = System.currentTimeMillis();
	/**
	 * 创建时间
	 */
	private Date createTime = new Date();

	private long visitCount = 1;

	/**
	 * 令牌状态,0:有效,1：已销毁
	 */
	private String status = SsoTokenInfo.OK;
	/**
	 * 令牌状态:有效
	 */
	public static final String OK = "0";
	/**
	 * 令牌状态:已销毁
	 */
	public static final String DESTROYED = "1";
	/**
	 * Token不匹配
	 */
	public static final String ERROR_CODE_INVALID_TOKEN = "01010001";
	/**
	 * 客户端或服务端信息不匹配
	 */
	public static final String ERROR_CODE_UNMATCHED_INFO = "01010002";
	/**
	 * Token过期
	 */
	public static final String ERROR_CODE_TOKEN_TIMEOUTED = "01010003";

	/**
	 * 传递的token参数不正确
	 */
	public static final String ERROR_CODE_REQUEST_TOKEN_ERROR = "01010004";
	/**
	 * 未知错误
	 */
	public static final String ERROR_CODE_UNKNOWN_OTHER = "01010099";

	/**
	 * @return the userId
	 */
	public String getUserId() {
		return userId;
	}

	/**
	 * @param userId
	 *            the userId to set
	 */
	public void setUserId(String userId) {
		this.userId = userId;
	}

	/**
	 * @return the updateTime
	 */
	public long getUpdateTime() {
		return updateTime;
	}

	/**
	 * @param updateTime
	 *            the updateTime to set
	 */
	public void refreshUpdateTime() {
		this.updateTime = System.currentTimeMillis();
	}

	public void refreshUpdateTime(long timeSpan) {
		long ut = System.currentTimeMillis() - timeSpan;
		if (ut > this.updateTime)
			this.updateTime = ut;
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @param status
	 *            the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	public String getUserCode() {
		return userCode;
	}

	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getOrgId() {
		return orgId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getOrgName() {
		return orgName;
	}

	public void setOrgName(String orgName) {
		this.orgName = orgName;
	}

	public String getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(String departmentId) {
		this.departmentId = departmentId;
	}

	public String getDepartmentCode() {
		return departmentCode;
	}

	public void setDepartmentCode(String departmentCode) {
		this.departmentCode = departmentCode;
	}

	public String getDepartmentName() {
		return departmentName;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public String getUserIp() {
		return userIp;
	}

	public void setUserIp(String userIp) {
		this.userIp = userIp;
	}

	public String getExplorerType() {
		return explorerType;
	}

	public void setExplorerType(String explorerType) {
		this.explorerType = explorerType;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public String getCheckCode() {
		return checkCode;
	}

	public void setCheckCode(String checkCode) {
		this.checkCode = checkCode;
	}

	public String getAppCode() {
		return appCode;
	}

	public void setAppCode(String appCode) {
		this.appCode = appCode;
	}

	public long getVisitCount() {
		return visitCount;
	}

	public void addVisitCount() {
		this.visitCount++;
	}

	public void setUpdateTime(long updateTime) {
		this.updateTime = updateTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public void setVisitCount(long visitCount) {
		this.visitCount = visitCount;
	}

}
